package com.star.common.orm.repository;

import com.star.common.orm.entity.QueryParam;
import com.star.common.orm.entity.Model;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 仓库上下文
 *
 * @author zhouhengzhe
 */
public class RepositoryRegistry {
    static Map<Class<?>, BaseRepository<? extends Model, ? extends QueryParam>> repositories = new ConcurrentHashMap<>();

    public static void register(Class<?> key, BaseRepository<?, ?> repository) {
        repositories.put(key, repository);
    }

    public static <T extends BaseRepository<D, Q>, D extends Model, Q extends QueryParam> T get(Class<?> key) {
        return (T) repositories.get(key);
    }
}
